<?php
class ControllerSoftInsurancereport extends Controller
{
	function index()
	{	
		$dt = getdate();
		$year = $dt['year'];
		$this->data['curentyear'] = $dt['year'];
		$this->data['curentmonth'] = $dt['mon'];
		for($i= $year - 10;$i<$year +10;$i++)
			$this->data["Year"][] =$i;
		for($i=1;$i<=12;$i++)
			$this->data["Month"][] =$i;
		$this->id='content';
		$this->template='soft/insurancereport.tpl';
		$this->layout='layout/center';
		$this->render();
	}
	
	public function getList()
	{
		$startdate=$this->date->formatViewDate($this->request->get['startdate']);
		$enddate=$this->date->formatViewDate($this->request->get['enddate']);
		$this->data['listorder'] = $this->getListOrder($startdate,$enddate,"sale");
		$this->data['sum'] = 0;
		foreach($this->data['listorder'] as $key => $item)
		{
			$this->data['listorder'][$key]['insurance']	= $item['insurancepercent'] * $item['total'] / 100;
			$this->data['sum'] += $this->data['listorder'][$key]['insurance'];
		}
		
		
		
		$this->template='soft/insurancereportlist.tpl';
		$this->render();
	}
	
	
	
	function getListOrder($startdate,$enddate,$type)
	{
		$this->load->model("addon/order");
		$wherestart = "";
		$whereend = "";
		if($this->request->get['startdate'] !="")
			$wherestart = "AND orderdate >= '".$startdate."' ";
		if($this->request->get['enddate'] !="")
			$whereend = "AND orderdate  <= '".$enddate."'";
		$where = " AND `type` = '".$type."' AND insurancepercent > 0 
					".$wherestart."
					".$whereend."
					ORDER BY  `order`.`orderdate` DESC ";
		
		$list = $this->model_addon_order->getListOrder($where);
		return $list;
	}
}
?>